﻿namespace NovellSecurity
{
  using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using System.Threading.Tasks;
  using Sitecore;
  using Sitecore.Caching;
  using Sitecore.Configuration;
  using Sitecore.Diagnostics;

  public class NovellRoleCache : CustomCache
  {
    /// <summary>
    /// Initializes a new instance of the <see cref="NovellRoleCache"/> class.
    /// </summary>
    public NovellRoleCache() : base("NovellRolesCache", StringUtil.ParseSizeString(Settings.GetSetting("Novell.Caching.RolesCacheSize")))
    {
    }

    /// <summary>
    /// Gets the role.
    /// </summary>
    /// <param name="roleName">Name of the role.</param>
    /// <returns></returns>
    public NovellRole GetRole(string roleName)
    {
      Assert.ArgumentNotNullOrEmpty(roleName, "roleName");
      return (NovellRole)base.GetObject(roleName);
    }

    /// <summary>
    /// Adds the role.
    /// </summary>
    /// <param name="role">The role.</param>
    public void AddRole(NovellRole role)
    {
      Assert.ArgumentNotNull(role, "role");
      base.SetObject(role.Name.ToLower(), role, StringUtil.ParseSizeString("1KB"));
    }
  }
}
